package org.jeecg.modules.demo.socket.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.modules.demo.socket.service.PushService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Api(tags="推送消息")
@RestController
@RequestMapping("/push")
@Slf4j
public class PushController {
    @Autowired
    private PushService pushService;
    /**
     * 推送给所有用户
     * @param msg
     */
    @PostMapping("/pushAll")
    @AutoLog(value = "推送个所有用户")
    @ApiOperation(value="推送给所有用户", notes="推送给所有用户")
    public Result<String> pushToAll(@RequestParam("msg") String msg){
        pushService.pushMsgToAll(msg);
        return Result.OK("推送成功");
    }
    /**
     * 推送给指定用户
     * @param userId
     * @param
     */
    @PostMapping("/pushOne")
    @AutoLog(value = "推送给指定用户")
    @ApiOperation(value="推送给指定用户", notes="推送给指定用户")
    public Result<String> pushMsgToOne(@RequestParam("userId") List<String> userId){
        for (String s : userId) {
            pushService.pushMsgToOne(s);
        }
        return Result.OK("推送成功");
    }

}
